home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 923 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. From: tony@online.tmx.com.au (Tony Cook)
  2. Message-ID: <199603312308.JAA29018@online.tmx.com.au>
  3. X-Original-Date: Mon, 1 Apr 1996 09:08:43 +1000
  4. Path: in2.uu.net!bounce-back
  5. Date: 01 Apr 96 04:13:59 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: double const declarations
  9. Organization: Home
  10. References: <4jc2fa$bqu@arl-news-svc-2.compuserve.com> <4jdvnj$o35@mulga.cs.mu.OZ.AU> <QQajel16319.199603292150@relay1.UU.NET>
  11. X-Newsreader: TIN [version 1.2 PL2]
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMV9Ye+EDnX0m9pzZAQH9hQF/ajcQGL1RX5XoeYP6FfcrhO7SLlemwlON
  14.     x6cOtMR1rYVjdBlqfSEy0dT+BEgL0krN
  15.     =LR1x
  16.  
  17. James Christodouleas (jchristo@mit.edu) wrote:
  18. : In article <4jdvnj$o35@mulga.cs.mu.OZ.AU>, fjh@munta.cs.mu.OZ.AU (Fergus
  19. : Henderson) wrote:
  20.  
  21. : > Philippe Verdy <100105.3120@compuserve.com> writes:
  22. : > 
  23. : > >template <class T, class CT>
  24. : > >class SmartPtr2  {
  25. : > >   SmartPtr2(T* p) { mp = const_cast<CT>(p) ; }
  26. : > >   CT & Dereference() {
  27. : > >     return *mp ;
  28. : > >   }
  29. : > > private :
  30. : > >   CT *mp ;
  31. : > >} ;
  32. : > >template <class T> class ConstSmartPtr : SmartPtr<T, T> {} ;
  33. : > >template <class T> class FreeSmartPtr : SmartPtr<T, const T> {} ;
  34. : > 
  35. : > You forgot to delegate the constructors.
  36. : > 
  37. : > (Of course, if C++ supported tempate typedefs, there wouldn't be
  38. : > any need to delegate constructors in examples like this.
  39. : > Unfortunately it doesn't.)
  40.  
  41. : What does it mean to "delegate constructors?"  I looked it up in Coplien,
  42. : Advanced C++, and he talks about delegation to mean different classes
  43. : sharing functionality dynamically.  
  44.  
  45. He means that the new classes, ConstSmartPtr and FreeSmartPtr do not
  46. have constructors, and cannot be created, so constructors that
  47. simply pass on the parameters are required (delegation).
  48.  
  49. There's another problem anyway - Phillippe used private inheritence,
  50. so a user cannot access the Dereference member function anyway.
  51.  
  52.     [Moderator's note: and `SmartPtr' should be `SmartPtr2',
  53.      and `const_cast<CT>' should be `const_cast<CT*>'.  This is
  54.      why it is a good idea to try compiling your examples
  55.      before posting them ;-).  -fjh. ]
  56.  
  57. -- 
  58.         Tony Cook - tony@online.tmx.com.au
  59.                     100237.3425@compuserve.com
  60. ---
  61. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  62. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  63. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  64. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  65. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  66.